/**
 * @param {number} numBottles
 * @param {number} numExchange
 * @return {number}
 */
var numWaterBottles = function (numBottles: number, numExchange: number): number {
  let exChang = (bottle: number, drink: number, k: number) => {
    if (k < numExchange && bottle < 1) {
      return drink
    }
    return exChang(Math.floor((bottle + k) / numExchange), drink + bottle, (bottle + k) % numExchange)
  }
  return exChang(numBottles, 0, 0)

};

console.log(numWaterBottles(9, 3))